package com.example.control;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.entry.User;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import sun.plugin2.main.server.CookieSupport;

import java.util.*;


//测试用例
public class CreationTimeSpader {
    public static void main(String[] args) {

        //        字符串拼接
        String url = "https://user.qzone.qq.com/proxy/domain/r.qzone.qq.com/cgi-bin/tfriend/friend_show_qqfriends.cgi?uin=1776999052&follow_flag=1&groupface_flag=0&fupdate=1&g_tk=1371663330&g_tk=1371663330";
        // 创建 HttpClient 对象，用于发送请求
        CloseableHttpClient httpClient = HttpClients.createDefault();
        // 因为使用的是 GET 请求，所以创建一个 HttpGet 对象
        HttpGet httpGet = new HttpGet(url);
        // 写入请求头参数
//        httpGet.setHeader("user-agent", "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Mobile Safari/537.36 Edg/102.0.1245.30");//102.0.5005.63
        httpGet.setHeader("Cookie","pgv_pvid=8284770148; eas_sid=d1l6X4a5O1s9J3V06130D1q7k7; RK=jifUagYxWt; ptcz=f8406990f3706d649686eb3b742afc9a45247e64685ab9837621e90851eab26c; qz_screen=1536x864; QZ_FE_WEBP_SUPPORT=1; __Q_w_s_hat_seed=1; __Q_w_s__QZN_TodoMsgCnt=1; pac_uid=1_1776999052; iip=0; luin=o1776999052; lskey=0001000012e108be17ac2448d9220a84354974042a2f3cc5ec9928054467a9dff3e2d5b5735fd6d8756ba18d; ptui_loginuin=1776999052; pt_sms_phone=173******20; Loading=Yes; ariaDefaultTheme=undefined; cpu_performance_v8=10; uin=o1776999052; skey=@D0RcZOaoJ; p_uin=o1776999052; pt4_token=-SDegUFEccTnTB58JOViy-sIqdUDi0wf66*gb-qacbc_; p_skey=1kmmKaOqZWrRp9PpKxigRUIOso9TRu-LmtcTCoyArts_; pgv_info=ssid=s3090011080; qzmusicplayer=qzone_player_1776999052_1654430178404; qqmusic_uin=; qqmusic_key=; qqmusic_fromtag=");
        // 创建一个 HttpResponse 用于接受请求结果
        CloseableHttpResponse response = null;
        try {
            // 发送请求
            response = httpClient.execute(httpGet);
//            System.out.println(response);
            // 将返回的结果转换为 JSONObject 类型，便与解析
//            JSONObject object = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
            // 因为返回的结果中包含 10 条评论，因此将所有的评论存储到 JSONArray 对象中
//            JSONArray rawComment = JSONArray.parseArray(String.valueOf(object.get("items")));
//            System.out.println(JSONArray.parseArray(String.valueOf(object.get("items"))));

//            list集合以存储爬取数据信息
//            List<String> strings = new ArrayList<>();

            // 对 JSONArray 对象进行遍历，拿到所有的评论，其他的信息可根据字段名自行捕获
//            for (Object and : rawComment) {
                //这里的url2
//                System.out.println(and);
//                System.out.println(strings.add(((JSONObject) and).get("uin").toString()));
//            }

        } catch (Exception e) {
            // 请求异常捕获
            System.out.println("发送请求失败，请检查您的网络");
        } finally {
            // 请求完毕，关闭 Http 对象
            if (response != null) {
                try {
                    response.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            try {
                httpClient.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }


}